<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>微信登录页</title>
    <script src="css/jquery.min.js"></script>
    <script src="js/0_common/bootstrap.js"></script>
    <script src="js/0_common/common.js"></script>
    <script src="js/constants.js"></script>
</head>
<style>
    body,html{
        width:100%;
        height:100%;
        overflow: hidden;
    }
    #wxlogin{
        width:80%;
        height: 50%;
        margin-left: 10%;
        margin-top: 45%;
        background-image: url("img/wxdl.png");
        background-size: 100% 100%;
    }
    #djlogin{
        cursor: pointer;
        background-image: url("img/wxdllogin.png");
        background-size: 100% 100%;
        height:3vh;
    }
    .input-val {
        width: 40%;
        height: 3vh;;
        box-sizing: border-box;
        line-height: 35px;
        color: #555;
        background-color: #fff;
        background-image: none;
        border: 1px solid #ccc;
        border-radius: 4px;
    }
    #canvas {
        vertical-align: middle;
        box-sizing: border-box;
        border: 1px solid #ccc;
        border-radius: 4px;
        cursor: pointer;
        margin-top: -5px;
    }
    #wxlogin input{
        background:rgba(219,220,226,1);
        border:2px solid rgba(255, 255, 255, 1);
        border-radius:5px;
        font-size:34px;
    }
    .line_m{
        text-decoration:line-through;
        color: #A6A9B2;

    }
    a{text-decoration: none;}
</style>
<body style="width:100%;height:100%;background-image: url('img/wxbg.png');background-size: 100% 100%;">
<div id="wxlogin">
    <!--<div style="width:55%;margin-left: 23%;margin-top: 31%">-->
    <div style="width:55%;position: relative;top:34%;left:26%">
        <span style="font-size:34px;font-family:Source Han Sans CN;font-weight:400;color:rgba(255,255,255,1);line-height:3vh;float: left">用户名&nbsp;&nbsp;</span>
        <input type="text" class="form-control" placeholder="" style="width:60%;height:3vh;;float: left" id="user">
    </div>
    <div style="width:55%;position: relative;top:39%;left:26%">
    <!--<div style="width:55%;margin-left: 23%;margin-top: 43%">-->
        <span style="font-size:34px;font-family:Source Han Sans CN;font-weight:400;color:rgba(255,255,255,1);line-height:3vh;float: left">密&nbsp;&nbsp;&nbsp;码&nbsp;&nbsp;</span>
        <input type="password" class="form-control" placeholder="" style="width:60%;height:3vh;;float: left;margin-left: 1%" id="mm">
    </div>
    <div style="width:55%;position: relative;top:44%;left:26%;height:0px">
    <!--<div style="width:65%;margin-left: 23%;margin-top: 55%">-->
        <span style="font-size:34px;font-family:Source Han Sans CN;font-weight:400;color:rgba(255,255,255,1);line-height:3vh;float: left">验证码&nbsp;&nbsp;</span>
        <input type="text" value="" placeholder="" class="input-val" >
        <canvas id="canvas" width="100" height="50" style="background-color: white"></canvas>
    </div>
    <div style="width:50%;position: relative;top:69%;left:26%" id="djlogin">
    </div>
    <div style="width:66%;position: relative;top:65%;left:11%;">

        <input name='subject' type="checkbox" value="mm" style="float:left;width:35px;height: 35px"/>
        <span style="font-size:34px;font-family:Source Han Sans CN;font-weight:400;color:rgba(255,255,255,1);line-height:3vh;float: left">记住密码</span>
        <a href="WJMM.html"><span style="font-size:34px;font-family:Source Han Sans CN;font-weight:400;color:rgba(255,255,255,1);line-height:3vh;float: right">忘记密码？</span></a>
    </div>
    <div style="position: absolute;top:75%;left:20%">
    <span class="line_m">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-size:34px;">如果没有账号？</span><a href="QYManage.html"> <span style="color: #46AFD8;font-size:34px;">请注册</span></a>
        <span class="line_m">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
    </div>
</div>
</body>
<script>
    var svcHeader=Constants.path;
    $(function(){
        var show_num = [];
        draw(show_num);
        $("#canvas").on('click',function(){
            draw(show_num);
        })
        $("#djlogin").click(function () {
            var val = $(".input-val").val().toLowerCase();
            var num = show_num.join("");
            if(val==''){
                alert('请输入验证码！');
            }else if(val == num){
                // alert('提交成功！');
                // $(".input-val").val('');
                var obj1={
                    'password':$('#mm').val(),
                    'name':$('#user').val()
                };
                // var a= p.test($('#mm').val());
                // var b= p1.test($('#mm').val());
                $.ajax({
                    url:svcHeader+"qyxxs/login",
                    dataType: 'json',
                    type: 'POST',
                    data: obj1,
                    success: function (data) {
                        console.log(data)
                        if(data.msg =='success'){
                            data=data.data;
                            localStorage.setItem('qyid',data.id);
                            localStorage.setItem('qymc',data.name);
                            $.ajax({
                                url: svcHeader + "pb/orcode/sc/"+data.id,
                                dataType: 'json',
                                type: 'get',
                                success: function (data) {
                                    console.log(data)
                                },error:function (data) {
                                    console.log(data,'aaa')
                                    var pic=data.responseText;
                                    localStorage.setItem('pic',pic);
                                    window.location.href="main.html";
                                }
                            })

                            // if(checkPass($('#mm').val())<3||$('#mm').val().length<8||$('#mm').val().length>20){
                            //
                            //     alert("系统检测到您的密码过于简单，建议修改！")
                            //     window.location.href="../changePower/changePower.html";
                            // }else{
                            //     window.location.href="BHMain/BHmain.html";
                            // }
                        }else{
                            alert("登陆失败！")
                        }
                    },
                    error: function (data) {
                        console.log(data,'aaa')
                        if(data.msg ==success){
                            data=data.data;
                            localStorage.setItem('qyid',data.id);
                            localStorage.setItem('qymc',data.name);
                            window.location.href="main.html";
                            // if(checkPass($('#mm').val())<3||$('#mm').val().length<8||$('#mm').val().length>20){
                            //
                            //     alert("系统检测到您的密码过于简单，建议修改！")
                            //     window.location.href="../changePower/changePower.html";
                            // }else{
                            //     window.location.href="BHMain/BHmain.html";
                            // }
                        }else{
                            alert("登陆失败！")
                        }
                    }
                })
                // draw(show_num);
            }else{
                alert('验证码错误！请重新输入！');
                $(".input-val").val('');
                // draw(show_num);
            }

        })
    })
    //生成并渲染出验证码图形
    function draw(show_num) {
        var canvas_width=$('#canvas').width();
        var canvas_height=$('#canvas').height();
        var canvas = document.getElementById("canvas");//获取到canvas的对象，演员
        var context = canvas.getContext("2d");//获取到canvas画图的环境，演员表演的舞台
        canvas.width = canvas_width;
        canvas.height = canvas_height;
        var sCode = "a,b,c,d,e,f,g,h,i,j,k,m,n,p,q,r,s,t,u,v,w,x,y,z,A,B,C,E,F,G,H,J,K,L,M,N,P,Q,R,S,T,W,X,Y,Z,1,2,3,4,5,6,7,8,9,0";
        var aCode = sCode.split(",");
        var aLength = aCode.length;//获取到数组的长度
        for (var i = 0; i < 4; i++) { //这里的for循环可以控制验证码位数（如果想显示6位数，4改成6即可）
            var j = Math.floor(Math.random() * aLength);//获取到随机的索引值
            // var deg = Math.random() * 30 * Math.PI / 180;//产生0~30之间的随机弧度
            var deg = Math.random() - 0.5; //产生一个随机弧度
            var txt = aCode[j];//得到随机的一个内容
            show_num[i] = txt.toLowerCase();
            var x = 10 + i * 20;//文字在canvas上的x坐标
            var y = 20 + Math.random() * 8;//文字在canvas上的y坐标
            context.font = "bold 23px 微软雅黑";
            context.translate(x, y);
            context.rotate(deg);
            context.fillStyle = randomColor();
            context.fillText(txt, 0, 0);
            context.rotate(-deg);
            context.translate(-x, -y);
        }
        for (var i = 0; i <= 5; i++) { //验证码上显示线条
            context.strokeStyle = randomColor();
            context.beginPath();
            context.moveTo(Math.random() * canvas_width, Math.random() * canvas_height);
            context.lineTo(Math.random() * canvas_width, Math.random() * canvas_height);
            context.stroke();
        }
        for (var i = 0; i <= 30; i++) { //验证码上显示小点
            context.strokeStyle = randomColor();
            context.beginPath();
            var x = Math.random() * canvas_width;
            var y = Math.random() * canvas_height;
            context.moveTo(x, y);
            context.lineTo(x + 1, y + 1);
            context.stroke();
        }
    }
    //得到随机的颜色值
    function randomColor() {
        var r = Math.floor(Math.random() * 256);
        var g = Math.floor(Math.random() * 256);
        var b = Math.floor(Math.random() * 256);
        return "rgb(" + r + "," + g + "," + b + ")";
    }
</script>
</html>